package com.iot.controller;

import com.iot.core.JsonHelper;
import com.iot.core.LResult;
import com.iot.pojo.MTrole_authority;
import com.iot.service.Trole_authorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/system/auth/")
public class TRole_authorityController extends BaseController  {
    @Autowired
    private Trole_authorityService service;
    @ResponseBody
    @RequestMapping("save")
    public String save(@RequestParam String bean) {
        try {

            MTrole_authority entity = JsonHelper.toBean(bean, MTrole_authority.class);
            if (entity.getROLE_AUTHORITY_ID() > 0) {
                service.update(entity);
            } else {
                service.insert(entity);

            }
            return LResult.Success(entity.getROLE_AUTHORITY_ID()).toJson();
        } catch (Exception ex) {
            return LResult.Error(ex.getMessage()).toJson();
        }
    }
    @ResponseBody
    @RequestMapping("get")
    public String getByid(@RequestParam Integer id) {
        try {
            //  String menu = request.getParameter("menu");
            MTrole_authority bean = service.single(id);
            return LResult.Success(bean).toJson();
        } catch (Exception ex) {
            return LResult.Error(ex.getMessage()).toJson();
        }
    }

    @ResponseBody
    @RequestMapping("del")
    public String deleteByid(@RequestParam Integer id) {
        try {
            //  String menu = request.getParameter("menu");
            service.deleteById(id);
            return LResult.Success().toJson();
        } catch (Exception ex) {
            return LResult.Error(ex.getMessage()).toJson();
        }
    }
}
